package gui.actions;

import java.awt.Container;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JFileChooser;
import javax.swing.JMenuItem;
import javax.swing.filechooser.FileNameExtensionFilter;

import controller.Controller;

public class ReadLogAction extends AbstractAction {
	private static final long serialVersionUID = 1L;

	public ReadLogAction(){
		putValue(NAME, "Read saved log file");
	}
	
	@Override
	public void actionPerformed(ActionEvent arg0) {
		JFileChooser chooser = new JFileChooser();
		chooser.setFileFilter(new FileNameExtensionFilter("XML Files (*.xml)", "xml"));
		JMenuItem src = (JMenuItem) arg0.getSource();
		Container parent = src.getParent();
		int returnVal = chooser.showOpenDialog(parent);
		
		if (returnVal == JFileChooser.APPROVE_OPTION){
			Controller.getInstance().readLog(chooser.getSelectedFile());
		}
	}

}
